﻿using System;
using System.IO;
using System.Reflection;
using log4net;
using log4net.Config;

namespace M
{
	/// <summary>
	/// M内部日志记录器
	/// </summary>
	public sealed class MLogger
	{
		private static readonly ILog log = LogManager.GetLogger("MLogger");
        static string ExePath = new DirectoryInfo(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName).Parent.FullName;
		/// <summary>
		/// 内部静态构造
		/// </summary>
		static MLogger()
        {
            XmlConfigurator.Configure(new FileInfo(Path.Combine(ExePath,"log4net.config")));
        }
		/// <summary>
		/// 记录调试信息
		/// </summary>
		/// <param name="message">调试信息</param>
        public static void Debug(string message)
        {
			if (log.IsDebugEnabled)
				log.Debug(message);
        }
		/// <summary>
		/// 格式化形式记录调试消息
		/// </summary>
		/// <param name="format">一般调试消息格式</param>
		/// <param name="args">格式化参数</param>
		public static void DebugFormat(string format, params object[] args)
		{
			if (log.IsDebugEnabled)
				log.DebugFormat(format, args);
		}
		/// <summary>
		/// 记录一般消息
		/// </summary>
		/// <param name="message">消息</param>
        public static void Info(string message)
        {
            if (log.IsInfoEnabled)
                log.Info(message);
        }
		/// <summary>
		/// 格式化形式记录一般消息
		/// </summary>
		/// <param name="format">一般消息格式</param>
		/// <param name="args">格式化参数</param>
        public static void InfoFormat(string format, params object[] args)
        {
            if (log.IsInfoEnabled)
				log.InfoFormat(format, args);
        }
		/// <summary>
		/// 记录警告消息
		/// </summary>
		/// <param name="message">消息</param>
		public static void Warn(string message)
		{
			if (log.IsWarnEnabled)
				log.Warn(message);
		}
		/// <summary>
		/// 格式化形式记录警告消息
		/// </summary>
		/// <param name="format">警告消息格式</param>
		/// <param name="args">格式化参数</param>
		public static void WarnFormat(string format, params object[] args)
		{
			if (log.IsWarnEnabled)
				log.WarnFormat(format, args);
		}

		/// <summary>
		/// 记录错误信息
		/// </summary>
		/// <param name="message">错误信息</param>
		public static void Error(string message)
		{
			if (log.IsErrorEnabled)
				log.Error(message);
		}
		/// <summary>
		/// 记录错误信息
		/// </summary>
		/// <param name="message">错误信息</param>
		/// <param name="err">和错误信息关联的异常</param>
		public static void Error(string message, Exception err)
		{
			if (log.IsErrorEnabled)
				log.Error(message, err);
		}
		/// <summary>
		/// 格式化形式记录错误信息
		/// </summary>
		/// <param name="format">错误信息格式</param>
		/// <param name="args">格式参数</param>
		public static void ErrorFormat(string format, params object[] args)
		{
			if (log.IsErrorEnabled)
				log.ErrorFormat(format, args);
		}

		/// <summary>
		/// 记录致命错误信息
		/// </summary>
		/// <param name="message">致命错误信息</param>
		public static void Fatal(string message)
		{
			if (log.IsFatalEnabled)
				log.Fatal(message);
		}
		/// <summary>
		/// 记录致命错误信息
		/// </summary>
		/// <param name="message">致命错误信息</param>
		/// <param name="err">和致命错误信息关联的异常</param>
		public static void Fatal(string message, Exception err)
		{
			if (log.IsFatalEnabled)
				log.Fatal(message, err);
		}
		/// <summary>
		/// 格式化形式记录致命错误信息
		/// </summary>
		/// <param name="format">致命错误信息格式</param>
		/// <param name="args">格式参数</param>
		public static void FatalFormat(string format, params object[] args)
		{
			if (log.IsFatalEnabled)
				log.FatalFormat(format, args);
		}
	}
}
